﻿using Abp.Application.Services;
using Abp.Domain.Repositories;
using AbpVueDemo.JichuxinxinDemo;
using AbpVueDemo.ShanjiDataManager.Dto;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AbpVueDemo.ShanjiDataManager
{
    public class SanjiDataService : AsyncCrudAppService<SanjiData, SanjiDataInputDto, int, PageSanjiDataRequestDto, SanjiDataCreateDto, SanjiDataUpdateDto>, ISanjiDataService
    {
        public SanjiDataService(
      IRepository<SanjiData, int> repository) : base(repository)
        {

        }
        [HttpGet] 
        public async Task<List<PageSanjiDataRequestDto>> SanJILianDong()
        {
            List<SanjiData> mlist = Repository.GetAllList();
            List<PageSanjiDataRequestDto> menuDbViews = new List<PageSanjiDataRequestDto>();
            var list = mlist.Where(c => c.fuji == "0");
            foreach (var item in list)
            {
                menuDbViews.Add(GetmenuDbView(mlist, item));
            }
            return menuDbViews;

        }
        private PageSanjiDataRequestDto GetmenuDbView(List<SanjiData> mlist, SanjiData parid)
        {
            PageSanjiDataRequestDto pageProvinceDataRequestDto = new PageSanjiDataRequestDto()
            {
                zhu = parid.zhu,
                fuji = parid.fuji,
                diqu = parid.diqu
            };
            var list = mlist.Where(c => c.fuji == pageProvinceDataRequestDto.zhu).ToList();
            if (list != null && list.Count > 0)
            {
                pageProvinceDataRequestDto.SonModules = new List<PageSanjiDataRequestDto>();
                foreach (var item in list)
                {
                    var temp = GetmenuDbView(mlist, item);
                    pageProvinceDataRequestDto.SonModules.Add(temp);
                }
            }

            return pageProvinceDataRequestDto;
        }
    }
}
